package tree;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
//https://leetcode.cn/leetbook/read/illustration-of-algorithm/7fs3j2/
//一棵圣诞树记作根节点为 root 的二叉树，节点值为该位置装饰彩灯的颜色编号。请按照从 左 到 右 的顺序返回每一层彩灯编号。
public class 彩灯装饰记录1 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    class Solution {
        public int[] decorateRecord(TreeNode root) {
            if(root == null) return new int[0];
            Queue<TreeNode> queue = new LinkedList<>();
            ArrayList<Integer> ans = new ArrayList<>();
            queue.add(root);
            while (!queue.isEmpty()){
                TreeNode node = queue.poll();
                ans.add(node.val);
                if(node.left != null) queue.add(node.left);
                if(node.right!= null) queue.add(node.right);
            }
            int[] res = new int[ans.size()];
            for (int i=0; i<ans.size(); i++){
                res[i] = ans.get(i);
            }
            return res;
        }
    }
}
